package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CstReimburseDetails;
import com.ruoyi.system.service.ICstReimburseDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报销明细Controller
 * 
 * @author zjw
 * @date 2023-01-04
 */
@RestController
@RequestMapping("/cst/details")
public class CstReimburseDetailsController extends BaseController
{
    @Autowired
    private ICstReimburseDetailsService cstReimburseDetailsService;

    /**
     * 查询报销明细列表
     */
    @PreAuthorize("@ss.hasPermi('cst:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(CstReimburseDetails cstReimburseDetails)
    {
        startPage();
        List<CstReimburseDetails> list = cstReimburseDetailsService.selectCstReimburseDetailsList(cstReimburseDetails);
        return getDataTable(list);
    }

    /**
     * 导出报销明细列表
     */
    @PreAuthorize("@ss.hasPermi('cst:details:export')")
    @Log(title = "报销明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CstReimburseDetails cstReimburseDetails)
    {
        List<CstReimburseDetails> list = cstReimburseDetailsService.selectCstReimburseDetailsList(cstReimburseDetails);
        ExcelUtil<CstReimburseDetails> util = new ExcelUtil<CstReimburseDetails>(CstReimburseDetails.class);
        util.exportExcel(response, list, "报销明细数据");
    }

    /**
     * 获取报销明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('cst:details:query')")
    @GetMapping(value = "/{detailsId}")
    public AjaxResult getInfo(@PathVariable("detailsId") Long detailsId)
    {
        return success(cstReimburseDetailsService.selectCstReimburseDetailsByDetailsId(detailsId));
    }

    /**
     * 新增报销明细
     */
    @PreAuthorize("@ss.hasPermi('cst:details:add')")
    @Log(title = "报销明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CstReimburseDetails cstReimburseDetails)
    {
        return toAjax(cstReimburseDetailsService.insertCstReimburseDetails(cstReimburseDetails));
    }

    /**
     * 修改报销明细
     */
    @PreAuthorize("@ss.hasPermi('cst:details:edit')")
    @Log(title = "报销明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CstReimburseDetails cstReimburseDetails)
    {
        return toAjax(cstReimburseDetailsService.updateCstReimburseDetails(cstReimburseDetails));
    }

    /**
     * 删除报销明细
     */
    @PreAuthorize("@ss.hasPermi('cst:details:remove')")
    @Log(title = "报销明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailsIds}")
    public AjaxResult remove(@PathVariable Long[] detailsIds)
    {
        return toAjax(cstReimburseDetailsService.deleteCstReimburseDetailsByDetailsIds(detailsIds));
    }
}
